﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
using System.Reflection;
using AMStudio.Script;
using System.Data;

namespace AMStudio.Common
{
    public static class UserDB
    {
        private static ProductTagDAL db = new ProductTagDAL();
        public static Dictionary<string, User> UserTags;
        public static void Init()
        {
            try
            {
                UserTags = db.SelectAllMapper();
            }
            catch (Exception ex)
            {
                throw new Exception("UserDB Init Error:" + ex.Message);
            }
        }

        public static void Add(User user)
        {
            if(!UserTags.ContainsKey(user.UserName))
            {
                db.Add(user);
                UserTags.Add(user.UserName,user);
            }
        }

        public static void Update(User user)
        {
            //if (UserTags.ContainsKey(user.UserName))
            //{
                db.Update(user);
            //}
        }

        public static void Delete(string userName)
        {
            if (UserTags.ContainsKey(userName))
            {
                db.Delete(userName);
                UserTags.Remove(userName);
            }
        }

        public static User CurrentLoginUser = new User();
   }
}
